//上一步
function back(url)
{
	window.location.href=url;
}
//下发SAP
function send_IDs(action,tableId){
	var sendIds = "";
	$('#'+tableId).find("input[type='checkbox'][data-ckb-id]:checked").each(function(){
		sendIds += ";"+$(this).attr("data-ckb-id");
	});
	if(sendIds == ""){
		top.$.jBox.tip('请选择一条发送信息','warning');
	}else{
		$("#toSap").attr("disabled","disabled");
		document.listForm.sendIds.value = sendIds.substring(1);
		document.listForm.action = action;
		Oosp_Loading('正在发送，请稍等...');
		document.listForm.submit();
	}
}

function sendSingle(action,id){
	$("#"+id).attr("disabled","disabled");
	Oosp_Loading('正在同步，请稍等...');
	window.open(action,'_self');
}
//-------------------弹出对话框
function openDialog(url,modalName){
	$("#"+modalName).load(url,function(){ 
	    $("#"+modalName).modal("show");  
	}); 
}

function openTempleteSelector(url,iWidth,iHeight){
	var iTop = (window.screen.availHeight - 20 - iHeight) / 2;  
    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;  
	var returnValue = window.showModalDialog(url,window,"dialogTop:"+iTop+"px;dialogLeft:"+iLeft+"px;location=no;center:Yes;dialogHeight:"+iHeight+"px;dialogWidth:"+iWidth+"px;status:No;help:No;");
	//for chrome  
	if (typeof(returnValue) == 'undefined') {  
		returnValue = window.localStorage.getItem("windowReturnValue");
		window.localStorage.removeItem("windowReturnValue");
	}  
	return eval('(' + returnValue + ')');
}
function templeteSelector_OK(dateType)
{
	//{"name":"value"}
	var jsonStr = "";
	if(dateType == "supplier")
	{
		$('#table1').find("input[type='radio'][data-ckb-id]:checked").each(function(){
			var supplierId = $(this).attr("data-ckb-id");
			var supplierNo = $(this).parent().parent().find("td[id='supplierNo']").text();
			var supplierName = $(this).parent().parent().find("td[id='supplierName']").text();
			jsonStr = '{"dataType":"'+dateType+'","supplierInfo":"'+supplierName+'('+supplierNo+')'+'","supplierId":"'+supplierId+'"}';
		});
	}else if(dateType == "supplierBrand")
	{
		$('#table1').find("input[type='radio'][data-ckb-id]:checked").each(function(){
			var supplierId = $(this).attr("data-ckb-id");
			//var supplierNo = $(this).parent().parent().find("td[id='supplierNo']").text();
			var supplierName = $(this).parent().parent().find("td[id='supplierName']").text();
			var brandCname = $(this).parent().parent().find("td[id='brandCname']").text();
			//var brandNo = $(this).parent().parent().find("td[id='brandNo']").text();
			var cateName = $(this).parent().parent().find("td[id='cateName']").text();
			jsonStr = '{"dataType":"'+dateType+'","supplierCname":"'+supplierName+'","supplierId":"'+supplierId+'","brandCname":"'+brandCname+'","cateName":"'+cateName+'"}';
		});
	}else if(dateType == "brandCate")
	{
		$('#table1').find("input[type='radio'][data-ckb-id]:checked").each(function(){
			var brandCateId = $(this).attr("data-ckb-id");
			var brandNo = $(this).parent().parent().find("td[id='brandNo']").text();
			var cateName = $(this).parent().parent().find("td[id='cateName']").text();
			var brandCname = $(this).parent().parent().find("td[id='brandCname']").text();
			jsonStr = '{"dataType":"'+dateType+'","brandNo":"'+brandNo+'","brandCateId":"'+brandCateId+'","brandInfo":"'+brandCname+'('+brandNo+')/'+cateName+'"}';
		});
	}
	//var isChrome = window.navigator.userAgent.indexOf("Chrome");
	  window.localStorage.setItem("windowReturnValue",jsonStr);
	  window.returnValue=jsonStr;
	  window.close();  
}

function closeTempleteSelector()
{
	window.close();
}

function selectRow(id)
{ 
	document.getElementById(id).checked = "checked";
}

//------------------------品牌品类
/*function brandCateChecked(brandCateId,brandNo,brandName,cateName)
{ 
	document.getElementById(brandCateId).checked = "checked";
	$("#hBrandCateId").val(brandCateId);
	$("#hBrandCname").val(brandName);
	$("#hCateName").val(cateName);
	$("#hBrandNo").val(brandNo);
}
//-------------------------供应商
function supplierChecked(supplierId,supplierName,supplierNo)
{ 
	document.getElementById(supplierId).checked = "checked";
	$("#hSupplierName").val(supplierName);
	$("#hSupplierId").val(supplierId);
	$("#hSupplierNo").val(supplierNo);
}
//-------------------------供应商品牌
function supplierBrandChecked(supplierId,brandCname,cateName,supplierCname)
{ 
	document.getElementById(supplierId).checked = "checked";
	$("#hSupplierCname").val(supplierCname);
	$("#hSupplierId").val(supplierId);
	$("#hBrandCname").val(brandCname);
	$("#hCateName").val(cateName);
}*/
//百货、综超相关级联数据
function loadBrandLevelByBrandType(brandType)
{
	if(brandType == "0")//目前统一使用百货等级
	{
		brandType = "1";
	}
	var contextPath = Com_Parameter.ContextPath;
	$.get(contextPath + '/biz/brand/level/'+ brandType + '/getLevelByBtype', function(data) {
		var jsonObj = eval('(' + data + ')');
		var jsonRoot = jsonObj.jsonRoot;
		$("#levelId").find("option").remove();
		$("#levelId").append("<option value=''>--请选择--</option>");
		for (var i = 0; i < jsonRoot.length; i++) {
			var obj = jsonRoot[i];
			$("#levelId").append("<option value='" + obj.levelId + "'>"+ obj.levelName + "</option>");
			$("#levelId").children("option").each(function() {
				if($(this).val() == $("#hLevel").val()){
				$(this).attr("selected","selected");
				}
			});
		}
	});
}


function S_Checked(id,eid)
{
	if($("#"+eid).attr("checked") == "checked")
	{
		$("#"+id).attr("checked","checked");
	}
	else
	{
		var sendIds = "";
		$('#'+id).parent().parent().find("input[type=checkbox][name=shop]:checked").each(function(){
				sendIds = "aa";
		});
		if(sendIds == ""){
			$("#"+id).removeAttr("checked");
		}
	}
}

function R_Checked(id)
{
	$('#'+id).parent().parent().find("input[type=checkbox][name=shop]").each(function(){
			if($("#"+id).attr("checked") == "checked")
			{
				$(this).attr("checked","checked"); 
			}else
			{
				$(this).removeAttr("checked"); 
			}
	});
}

function loadShopData(url)
{
	var contextPath = Com_Parameter.ContextPath;
	var id = $("#id").val();
	if(null == id || id.length < 1){
		id = "ALL";
	}
	$.get(contextPath + url, function(data) {
		var jsonObj = eval('(' + data + ')');
		var jsonRoot = jsonObj.jsonRoot;
		var str="";
		for (var i = 0; i < jsonRoot.length; i++) 
		{
			var region = jsonRoot[i];
			var shops = region.shopList;
			str+="<tr>";
			str+="<td><input type='checkbox' id='"+region.code+"' name='region' onclick='R_Checked("+region.code+")' ";
			if(null == shops || shops.length <1)
			{
				str+=" disabled='disabled' ";
			}
			else if(region.checked == 'true')
			{
				str+=" checked='checked' ";
			}
			str+="/>"+region.name+"</td>";
			str+="<td><table><tr><td>";
			for (var j = 0; j < shops.length; j++) 
			{
				var shop = shops[j];
				str+="<input type='checkbox' id='"+shop.code+"' onclick='S_Checked("+region.code+","+shop.code+")' name='shop'";
				if(shop.checked == 'true')
				{
					str+=" checked='checked' ";
				}
				str+="/>"+shop.name;
			}
			str+="</td></tr></table></td>";
			str+="</tr>";
		}
		
		$("#shopData").append(str);
	});
}

function returnCheckedNos()
{
	var ids = "";
	$('#shopData').find("input[type=checkbox][name=shop]:checked").each(function(){
		ids +="##"+$(this).attr("id");
	});
	ids = ids.substring(2,ids.length);
	$("#checkinShopNos").val(ids);
}

/*
$(function() {
	//加载等级
	var contextPath = Com_Parameter.ContextPath;
	$.get(contextPath + '/biz/brand/level/'+ brandType + '/getLevelByBtype', function(data) {
		var jsonObj = eval('(' + data + ')');
		var jsonRoot = jsonObj.jsonRoot;
		for (var i = 0; i < jsonRoot.length; i++) {
			var obj = jsonRoot[i];
			$("#levelId").append("<option value='" + obj.levelId + "'>"+ obj.levelName + "</option>");
			$("#levelId").children("option").each(function() {
				if($(this).val() == $("#hLevel").val()){
				$(this).attr("selected","selected");
				}
			});
		}
	});
});*/
/*jquery*/
jQuery.validator.addMethod("mobile", function(value, element) {
	var length = value.length;
	var mobile = /^(((1[3587][0-9]{1})|(15[0-9]{1}))+\d{8})$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
	}, "Please enter a valid mobile no.");
jQuery.validator.addMethod("phone", function(value, element) {
	var tel = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/;
	return this.optional(element) || (tel.test(value));
	}, "Please enter a valid phone no.");

jQuery.validator.addMethod("organization", function(value, element) {
	var tel = /^[A-Za-z0-9]{8}-[A-Za-z0-9]{1}/;
	return this.optional(element) || (tel.test(value));
	}, "Please enter a valid organization code.");
jQuery.validator.addMethod("businessno", function(value, element) {
	var tel = /^\d{15}$/;
	return this.optional(element) || (tel.test(value));
	}, "Please enter a valid business license no.");
jQuery.validator.addMethod("landtaxno", function(value, element) {
	var tel = /^\d{15}$/;
	return this.optional(element) || (tel.test(value));
	}, "Please enter a valid tax registration no.");
/*jQuery.validator.addMethod("datarequired", function(value, element) {
	var tel = /^\s*$/;alert(tel.test(value));
	return this.optional(element) || (tel.test(value));
	}, "This field is required.");*/

